/*
题目描述
有两个链表a和b，设节点中包含学号、姓名。从a链表中删去b链表中有相同学号的那些节点。

输入
第一行有两个用空格隔开的整数n和m，分别表示a和b两个链表中的节点个数。保证n和m均不超过100。
之后的n行每行有两个用空格隔开的整数，分别表示一个学生的学号和成绩。
最后的m行每行有两个用空格隔开的整数，分别表示一个学生的学号和成绩。
a和b两个链表中的节点并不一定按照学号顺序排列。保证a链表中学号各不相同，b链表中学号各不相同。

输出
首先输出a链表最终剩下的节点个数k。
在接下来的k行，每行输出两个用空格隔开的整数，分别表示一个学生的学号和成绩。
请注意行尾输出换行。
*/
#include <stdio.h>
#include <stdlib.h>
typedef struct student
{
    int id;
    int score;
    struct student *next;
} Student;

Student *createNode(int id, int score)
{
    Student *newNode = (struct student *)malloc(sizeof(struct student));
    newNode->id = id;
    newNode->score = score;
    newNode->next = NULL;
    return newNode;
}

Student *insertNode(Student *List, int id, int score)
{
    Student *newNode = createNode(id, score);
    Student *head = List;
    Student *current = List;
    if (id < head->id)
    {
        newNode->next = head;
        return newNode;
    }
    while (current->next != NULL)
    {
        if (current->next->id > id)
        {
            newNode->next = current->next;
            current->next = newNode;
            return head;
        }
        else
        {
            current = current->next;
        }
    }
    current->next = newNode;
    return head;
}

Student *deleteNode(Student *List, int id)
{
    Student *head = List;
    Student *current = List;
    while (current != NULL)
    {
        // 头结点
        if (head->id == id)
        {
            Student *next = head->next;
            free(head);
            return next;
        }
        if (current->next != NULL && current->next->id == id)
        {
            Student *next = current->next;
            current->next = current->next->next;
            free(next);
            return head;
        }
        else
        {
            current = current->next;
        }
    }
    return head;
}

Student *buildList(int n)
{
    int id, score;
    scanf("%d %d", &id, &score);
    Student *head = createNode(id, score);
    for (int i = 1; i < n; i++)
    {
        int newId, newScore;
        scanf("%d %d", &newId, &newScore);
        head = insertNode(head, newId, newScore);
    }
    return head;
}

int getListLength(Student *List)
{
    int length = 0;
    Student *current = List;
    while (current != NULL)
    {
        length++;
        current = current->next;
    }
    return length;
}

void printList(Student *List)
{
    Student *head = List;
    Student *current = List;
    while (current != NULL)
    {
        printf("%d %d\n", current->id, current->score);
        current = current->next;
    }
}

int main()
{
    int a, b;
    scanf("%d %d", &a, &b);
    Student *listA = buildList(a);
    Student *listB = buildList(b);
    Student *current = listB;
    for (int i = 0; i < b; i++)
    {
        Student *delete = current;
        current = current->next;
        listA = deleteNode(listA, delete->id);
    }
    printf("%d\n",getListLength(listA));
    printList(listA);
}